package com.iqiyi.pps.epg.core.model.statistic;

import com.iqiyi.pps.epg.api.model.web.statistic.TStatisticOcrData;
import com.iqiyi.pps.epg.core.utils.DateTimeUtil;
import com.iqiyi.pps.epg.core.utils.StringUtil;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.sql.Timestamp;

/**
 * Created by zhang on 2016/1/25.
 */
@Entity
@Table(name="st_ocr_data")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class StatisticOcrData {

    private long id;
    private String channelId;
    private String channelName;
    private String programId;
    private String programName;
    private String categoryName;
    private String ocrReturnTitle;
    private String userSubmitTitle;
    private boolean same;
    private int realSamePercent;
    private String user;
    private Timestamp statisticTime = new Timestamp(System.currentTimeMillis());

    public StatisticOcrData() {
    }

    public void setSameField() {
        int precent = StringUtil.alikePercent(ocrReturnTitle, userSubmitTitle);
        if (precent == 100) {
            same = true;
        } else {
            same = false;
        }
        realSamePercent = precent;
    }

    public TStatisticOcrData convertThriftModel() {
        TStatisticOcrData tStatisticOcrData = new TStatisticOcrData();
        tStatisticOcrData.setId(this.getId());
        tStatisticOcrData.setChannelId(this.getChannelId());
        tStatisticOcrData.setChannelName(this.getChannelName());
        tStatisticOcrData.setProgramId(this.getProgramId());
        tStatisticOcrData.setProgramName(this.getProgramName());
        tStatisticOcrData.setCategoryName(this.getCategoryName());
        tStatisticOcrData.setOcrReturnTitle(this.getOcrReturnTitle());
        tStatisticOcrData.setUserSubmitTitle(this.getUserSubmitTitle());
        tStatisticOcrData.setIsSameTitle(this.isSame());
        tStatisticOcrData.setRealSamePercent(this.getRealSamePercent());
        tStatisticOcrData.setUser(this.getUser());
        tStatisticOcrData.setStatisticTime(DateTimeUtil.transLongFormat(this.getStatisticTime().getTime()));
        return tStatisticOcrData;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Column(name="channel_id")
    public String getChannelId() {
        return channelId;
    }

    public void setChannelId(String channelId) {
        this.channelId = channelId;
    }

    @Column(name="channel_name")
    public String getChannelName() {
        return channelName;
    }

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }

    @Column(name="program_id")
    public String getProgramId() {
        return programId;
    }

    public void setProgramId(String programId) {
        this.programId = programId;
    }

    @Column(name="program_name")
    public String getProgramName() {
        return programName;
    }

    public void setProgramName(String programName) {
        this.programName = programName;
    }

    @Column(name="category_name")
    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    @Column(name="ocr_return_title")
    public String getOcrReturnTitle() {
        return ocrReturnTitle;
    }

    public void setOcrReturnTitle(String ocrReturnTitle) {
        this.ocrReturnTitle = ocrReturnTitle;
    }

    @Column(name = "user_submit_title")
    public String getUserSubmitTitle() {
        return userSubmitTitle;
    }

    public void setUserSubmitTitle(String userSubmitTitle) {
        this.userSubmitTitle = userSubmitTitle;
    }

    @Column(name = "is_same_title")
    public boolean isSame() {
        return same;
    }

    public void setSame(boolean same) {
        this.same = same;
    }

    @Column(name = "real_same_percent")
    public int getRealSamePercent() {
        return realSamePercent;
    }

    public void setRealSamePercent(int realSamePercent) {
        this.realSamePercent = realSamePercent;
    }

    @Column(name = "user")
    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    @Column(name = "st_time")
    public Timestamp getStatisticTime() {
        return statisticTime;
    }

    public void setStatisticTime(Timestamp statisticTime) {
        this.statisticTime = statisticTime;
    }

}
